#include "CMainWindow.h"

#include <QHBoxLayout>
#include <QMap>
#include <QMessageBox>
#include <QPushButton>

#include "QProperty.h"
#include "QNumberProperty.h"
#include "QBoolProperty.h"
#include "QFileProperty.h"
#include "QColorProperty.h"
#include "QVector3DProperty.h"

#include "CIrrlichtWindow.h"

using namespace QPE;


CMainWindow::CMainWindow(QWidget *parent) :
	QMainWindow(parent), IrrlichtTimer(new QTimer(this))
{
	Irrlicht = new CIrrlichtWindow(this);

	// This time, our Property Model is of the type QIrrAttributesProxy.
	PropertyModel = new QIrrAttributesProxy(this);

	// Like in the first example, we create the tree view and set up the window
	TreeView = new QPropertyTreeView(PropertyModel, this);
	TreeView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
	setCentralWidget(new QWidget(this));
	setWindowTitle(tr("AnimatedMeshSceneNode"));

	QHBoxLayout* layout = new QHBoxLayout(this);
	centralWidget()->setLayout(layout);
	layout->setSpacing(5);
	layout->setMargin(0);
	layout->addWidget(TreeView);


	// We set up the timer, that calls the run()-slot of our Irrlicht class, so that Irrlicht can render
	IrrlichtTimer->start(60);
	IrrlichtTimer->setSingleShot(false);
	connect(IrrlichtTimer, SIGNAL(timeout()), Irrlicht, SLOT(run()));

	// Now, let's obtain the scene nodes attributes...
	irr::io::IAttributes* tmpAttributes = Irrlicht->createAttributes();

	// ...and set it to our property model, which takes the pointer to our attributes as argument
	PropertyModel->setAttributes(tmpAttributes);

	/* Because createAttributes creates a new object and the property model grabs it already,
	we can drop it after we assign it to the property model, because we don't need it anymore*/
	if(tmpAttributes)
		tmpAttributes->drop();

	// Finally, we connect the property model to our Irrlicht class, so that the attributes get updated.
	connect(PropertyModel, SIGNAL(attributesChangedByEditor(irr::io::IAttributes*)), Irrlicht, SLOT(onAttributesChangedByEditor(irr::io::IAttributes*)));
}

CMainWindow::~CMainWindow()
{
	// We don't need to do anything in the destructor
}

